package eu.winterwheels.enterprise.service.security;

import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import eu.winterwheels.enterprise.data.UserRepository;
import eu.winterwheels.enterprise.model.User;

// The @Stateless annotation eliminates the need for manual transaction demarcation
@Stateless
public class LoginService {

	@Inject
	private Logger log;

	@Inject
	private EntityManager em;
	
	@Inject
    private UserRepository repository;

	@Inject
	private Event<User> userEvent;

	public User login(User user) {
		log.info("login " + user.getUsername());

		User rUser = repository.findByCredentials(user.getUsername(), user.getPassword());
		return rUser;
		// User user = em.
		// userEvent.fire(user);
	}

	// public void register(Member member) throws Exception {
	// log.info("Registering " + member.getName());
	// em.persist(member);
	// memberEventSrc.fire(member);
	// }
}
